import { mapActions } from 'vuex'

export default {
  data() {
    return {
      active: 1,
      storePosters: [],
      onegood: [],
      manygood: [],
      owner: [],

    }
  },
  onLoad(option) {
    this.active = option.active ? parseInt(option.active) : 1
  },

  onShow() {
    this.getPosters()
  },
  methods: {
    ...mapActions([
      'setPosterType',
      'setPosterBgTemplate'
    ]),

    // 获取海报图片列表
    async getPosters() {
      try {
        const { data } = await this.$api.jsonData.getPosters()
        // 为每个海报图片列表添加对应海报的type类型标识
        this.storePosters = data.store.map(d => ({ ...d, type: 'store' }))
        this.onegood = data.onegood.map(d => ({ ...d, type: 'onegood' }))
        this.manygood = data.manygood.map(d => ({ ...d, type: 'manygood' }))
        this.owner = data.owner.map(d => ({ ...d, type: 'owner' }))
      } catch (err) {
        //
      }
    },
    clickOther(item) {
      this.active = item
    },

    // 跳转到编辑商品海报页面
    goSelectGoods(data, type) {
      const pagesMap = new Map([
        ['店铺海报', '/pages_common/pages_me/selectStore/selectStore'],
        ['单品海报', '/pages_common/pages_me/selectGoods/selectGoods'],
        ['多商品海报', '/pages_common/pages_me/selectGoods/selectGoods'],
        ['我的海报', '/pages_common/pages_me/storePoster/storePoster'],
      ])

      console.log('testtesttest',data,type)

      // data.url为背景图

      this.setPosterBgTemplate(data)
      this.setPosterType(type)
      uni.navigateTo({
			  url: `${pagesMap.get(type)}`,
        success: () => {},
        fail: err => {
          console.log(err)
        }
      })
    },

    // 测试分享功能
    shareTest() {
      uni.share({
			  provider: 'weixin',
			  scene: 'WXSceneSession',
			  type: 1, // 0图文  1纯文字  2纯图片
			  imageUrl: 'https://files.yzsheng.com/client/imgs/applogo.png',
			  // href: 'http://uniapp.dcloud.io/',
			  success: function(res) {
			    console.log('success:' + JSON.stringify(res))
			  },
			  fail: function(err) {
			    console.log('fail:' + JSON.stringify(err))
			  }
      })
    }
  }
}